Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added fee to price and balances query #2365

Merged
merged 7 commits into from
Jan 2, 2024
Merged

feat: added fee to price and balances query #2365

merged 7 commits into from
Jan 2, 2024

Conversation

kosegor
Copy link
Contributor

@kosegor kosegor commented Dec 22, 2023

Summary by CodeRabbit

  • New Features

    • Introduced a swap_fee field to financial transactions, affecting asset exchange and user fees.
  • Bug Fixes

    • Removed experimental build constraints, potentially stabilizing feature sets.
  • Refactor

    • Updated fee calculation logic with new return types and values for better precision.
    • Altered the redeem function to include fee handling during transactions.
  • Tests

    • Adjusted tests to align with the updated fee calculation logic.
  • Documentation

    • No visible changes to end-user documentation reported.

@kosegor kosegor requested a review from a team as a code owner December 22, 2023 16:09
Copy link
Contributor

coderabbitai bot commented Dec 22, 2023

Warning

Rate Limit Exceeded

@kosegor has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 9 minutes and 59 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between b7a83af and 005d5be.

Walkthrough

The updates across various files in the codebase revolve around the introduction and handling of new financial parameters—specifically, swap and redeem fees. These changes affect the calculation of fees, the logic of transactions, and test configurations. Fields have been added and renumbered in the protobuf definition, functions updated to return new fee-related values, and experimental build constraints removed, suggesting a shift towards stabilization of features.

Changes

File Path Change Summary
proto/umee/metoken/v1/metoken.proto Added swap_fee field; renumbered redeem_rate and redeem_fee.
util/coin/coin.go,
x/metoken/keeper/.../fee.go,
fee_test.go,
grpc_query.go,
price.go,
redeem.go,
swap.go
Added/updated functions and methods related to fee calculation.
x/metoken/client/tests/.../cli_test.go,
suite.go,
tests.go,
intest/grpc_query_test.go
Removed experimental build constraints; added/updated fields for testing.
x/metoken/mocks/metoken.go Modified function declaration and asset denomination.

🐇🎉
To the code that we enhance,
With fees in a dance,
Bugs scurry away in a prance,
As the rabbit codes with a glance. 🥕👩‍💻

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e3a9892 and f5ac4ad.
Files ignored due to filter (2)
  • swagger/swagger.yaml
  • x/metoken/metoken.pb.go
Files selected for processing (11)
  • proto/umee/metoken/v1/metoken.proto (1 hunks)
  • util/coin/coin.go (1 hunks)
  • x/metoken/client/tests/cli_test.go (1 hunks)
  • x/metoken/client/tests/suite.go (1 hunks)
  • x/metoken/client/tests/tests.go (2 hunks)
  • x/metoken/keeper/fee.go (2 hunks)
  • x/metoken/keeper/fee_test.go (4 hunks)
  • x/metoken/keeper/grpc_query.go (2 hunks)
  • x/metoken/keeper/price.go (3 hunks)
  • x/metoken/keeper/redeem.go (4 hunks)
  • x/metoken/keeper/swap.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • x/metoken/client/tests/cli_test.go
  • x/metoken/client/tests/suite.go
Additional comments: 13
util/coin/coin.go (1)
  • 58-61: The addition of the One function is correct and follows best practices for creating a new coin instance with an amount of one.
x/metoken/keeper/fee_test.go (1)
  • 34-55: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [25-52]

The changes to the swapFee and redeemFee functions, including the return of both a fraction and an amount for the fee, are correct. The tests have been updated to reflect these changes.

x/metoken/keeper/fee.go (1)
  • 10-37: The changes to the swapFee and redeemFee functions, including the updated return types and fee calculation logic, are correct.
x/metoken/client/tests/tests.go (1)
  • 106-108: The removal of the experimental build tag and the addition of SwapFee and RedeemFee to the data structure within the TestValidQueries function are correct and reflect the new fee logic in test scenarios.
x/metoken/keeper/grpc_query.go (1)
  • 75-80: The changes to the SwapFee and RedeemFee functions, including the addition of the feeAmount variable in the return values, are correct.
x/metoken/keeper/price.go (1)
  • 90-107: The addition of the coin package import and the new calculations for swapFee and redeemFee within the Prices method are correct and follow best practices.
proto/umee/metoken/v1/metoken.proto (1)
  • 151-169: The addition of the swap_fee field and the renumbering of redeem_rate and redeem_fee in the AssetPrice message are correct and follow protocol buffer best practices.
x/metoken/keeper/swap.go (1)
  • 203-214: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [206-221]

The changes in the calculateSwap function, including the replacement of the fee variable with feeAmount and the adjusted access patterns, are correct.

x/metoken/keeper/redeem.go (5)
  • 93-99: The function now correctly returns an additional sdk.Coin value for the fee amount. However, ensure that all callers of this function are updated to handle the new return value.

  • 96-99: The introduction of feeAmount calculation and its error handling is consistent with the existing code structure.

  • 114-114: The calculation of toRedeem correctly accounts for the fee by subtracting feeAmount.Amount from the total redeemable amount.

  • 130-130: The update to the balance.Fees field correctly adds the feeAmount.Amount, ensuring that fee balances are updated as expected.

  • 143-147: The newRedeemResponse function is correctly called with the new feeAmount parameter, reflecting the changes made to the redemption logic.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f5ac4ad and e5c14b3.
Files selected for processing (3)
  • x/metoken/keeper/intest/grpc_query_test.go (1 hunks)
  • x/metoken/keeper/price.go (2 hunks)
  • x/metoken/mocks/metoken.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/metoken/keeper/price.go
Additional comments: 2
x/metoken/mocks/metoken.go (1)
  • 127-129: The change from USDTBaseDenom to CMSTBaseDenom in EmptyNonStableIndexBalances should be verified to ensure it aligns with the new fee structures introduced in the PR. If CMSTBaseDenom is part of the non-stable assets that now include fees, this change is justified.
x/metoken/keeper/intest/grpc_query_test.go (1)
  • 371-373: The added assertions for SwapFee and RedeemFee being greater than zero are appropriate and align with the PR's objective to introduce fee components. This ensures that the fees are properly implemented and non-zero in the test scenarios.

Copy link

codecov bot commented Dec 22, 2023

Codecov Report

Attention: 119 lines in your changes are missing coverage. Please review.

Comparison is base (7f05ad4) 75.38% compared to head (005d5be) 70.05%.
Report is 328 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2365      +/-   ##
==========================================
- Coverage   75.38%   70.05%   -5.34%     
==========================================
  Files         100      174      +74     
  Lines        8025    12987    +4962     
==========================================
+ Hits         6050     9098    +3048     
- Misses       1589     3282    +1693     
- Partials      386      607     +221     
Files Coverage Δ
ante/ante.go 66.66% <100.00%> (+18.45%) ⬆️
ante/fee.go 80.00% <100.00%> (+1.64%) ⬆️
ante/spam_prevention.go 75.92% <ø> (ø)
app/inflation/inflation.go 100.00% <100.00%> (ø)
app/upgradev3/migrations.go 84.21% <ø> (+5.94%) ⬆️
util/coin/utoken.go 100.00% <100.00%> (ø)
util/ibc/ibc.go 58.82% <ø> (ø)
util/sdkutil/events.go 0.00% <ø> (ø)
util/store/store.go 52.06% <ø> (+10.65%) ⬆️
util/store/unmarshal.go 42.85% <ø> (ø)
... and 40 more

... and 113 files with indirect coverage changes

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e5c14b3 and ef3ba1f.
Files ignored due to filter (2)
  • swagger/swagger.yaml
  • x/metoken/metoken.pb.go
Files selected for processing (1)
  • proto/umee/metoken/v1/metoken.proto (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • proto/umee/metoken/v1/metoken.proto

@kosegor kosegor self-assigned this Dec 22, 2023
Copy link
Member

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please don't forget to add Changelog entries

x/metoken/keeper/fee.go Show resolved Hide resolved
x/metoken/keeper/price.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ef3ba1f and ad114dd.
Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • x/metoken/keeper/fee.go (2 hunks)
  • x/metoken/keeper/price.go (2 hunks)
Additional comments: 3
x/metoken/keeper/price.go (2)
  • 10-13: The addition of the coin package import is appropriate for the new functionality that requires creating a new coin instance with an amount of one. This is used in the calculation of swap and redeem fees.

  • 87-104: The modifications to the Prices method to calculate and assign swap and redeem fees are correctly implemented. The fees are calculated using the swapFee and redeemFee methods and assigned to the respective fields in the indexPrices.Assets structure. This aligns with the PR's objective to include fee calculations in price and balance queries.

CHANGELOG.md (1)

x/metoken/keeper/fee.go Outdated Show resolved Hide resolved
x/metoken/keeper/fee.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ad114dd and b7a83af.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

@kosegor kosegor added this pull request to the merge queue Jan 2, 2024
Merged via the queue into main with commit ed181c6 Jan 2, 2024
25 of 28 checks passed
@kosegor kosegor deleted the egor/metoken-qry branch January 2, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants